package com.lagou.consumer;

import com.lagou.common.pojo.Order;
import com.lagou.common.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

@Component
public class OverdueConsumer {

    @Autowired
    private OrderService orderService;


    @RabbitListener(queues = "payment.dlx")
    public void getMyMessage(@Payload Order message) {
        System.out.println(message);


        Order order = orderService.findById(message.getId());

        // 如果订单过期仍未支付，那么将订单标记过期
        if (order != null && order.getStatus().equals("paying")) {
            order.setStatus("overdue");
            orderService.save(order);
        }


    }
}
